package com.example.demo_mysql_mybatisplus.util;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyUtil {

    /**  ProxyUtil.run(customerApi).demo() */
    public static <T> T run(T instance) {
        Class<?> clazz = instance.getClass();
        return (T) Proxy.newProxyInstance(clazz.getClassLoader(), clazz.getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("Before method call");
                Object result = method.invoke(instance, args);
                System.out.println("After method call");
                return result;
            }
        });
    }
}
